package org.example.file.serialize;

import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestBase64 {

    private static final Logger logger = LoggerFactory.getLogger(TestBase64.class);

    private static final Base64.Decoder decoder = Base64.getDecoder();
    private static final Base64.Encoder encoder = Base64.getEncoder();

    public static void main(String[] args) throws Exception {

        List<Person> list = new ArrayList<>();
        int num = 100000000;
        for (int i = 0; i < num; i++) {
            Person person = new Person();
            person.setName(i + " ");
            person.setAge(i);
            if (i % 2 == 0) {
                person.setClothes(true);
            } else {
                person.setClothes(false);
            }

            person.setMoney(new byte[] {1, 2, 3});

            logger.info(person.toString());
            // list.add(person);
        }

        /*
        File file = new File("/Users/zhangjungang/test/pbase.txt");
        FileOutputStream fos = new FileOutputStream(file);
        ObjectOutputStream otm = new ObjectOutputStream(fos);
        for(Person p : list) {
            String s = encoder.encodeToString(p.toString().getBytes("UTF-8"));
        //            otm.writeUTF(s);
            logger.info(s);
        }
        otm.writeUTF("null");
        otm.flush();
        otm.close();
        fos.close();
        System.out.println("-------object write end!");
        
        FileInputStream fis = new FileInputStream(file);
        ObjectInputStream ois = new ObjectInputStream(fis);
        
        while (true){
            String pstr = ois.readUTF();
            if(!"null".equals(pstr) ) {
                System.out.println(new String(decoder.decode(pstr),"UTF-8"));
            }else {
                break;
            }
        }
        
        ois.close();
        fis.close();*/
        System.out.println("-------object read end!");
    }

}
